from typing import TypedDict, Optional

# 定义TypedDict
class User(TypedDict):
    name: str
    age: int
    email: str
    is_active: bool

# 可选字段的TypedDict
class UserWithOptional(TypedDict, total=False):
    name: str  # 必需字段
    age: int   # 必需字段
    email: Optional[str]  # 可选字段
    address: str  # 可选字段

# 使用TypedDict
def create_user(user_data: User) -> User:
    return user_data

# 创建符合类型的字典
new_user: User = {
    "name": "Alice",
    "age": 30,
    "email": "alice@example.com",
    "is_active": True
}